/*
 * @Date: 2022-12-14 17:19:33
 * @LastEditTime: 2023-02-09 14:46:19
 * @Description: 
 */
import IMyModel from "./IMyModel";
import { getSysList, getXtjcxx, updateUserInfo } from "@/utils/net";
import { useUserStore } from "@/stores/modules/user";
import { result } from "lodash";

export default class MyModelImp implements IMyModel {
    clearStorage(): Promise<void> {
        return new Promise((resolve, reject) => {
            getXtjcxx().then((result) => {
                let userLogin = result.data.data
                uni.clearStorageSync()
                useUserStore().setSys(userLogin.sys)
                useUserStore().setUser(userLogin.user)
                useUserStore().setToken(userLogin.sys.token)
                resolve(result.data.data)
            })
        })
    }

    getSysList(): Promise<Array<Object>> {
        return new Promise((resolve, reject) => {
            getSysList().then((result) => {
                if (result.data.status) {
                    resolve(result.data.data.list)
                }
            })
        })
    }

    checkSys(item: any): void {
        useUserStore().setCurrentSystemName(item.mc)
        useUserStore().setCurrentSystemCode(item.dm)
    }

    updateUserInfo(user: any): Promise<void> {
        return new Promise((resolve, reject) => {
            updateUserInfo(user).then((result) => {
                if (result.data.status) {
                    uni.showToast({
                        title: '更新成功'
                    });
                    uni.navigateBack()
                    resolve(result.data.data)
                }
            })
        })
    }

}
